﻿using System;
using System.Collections.Generic;

public class WarSoldier : WarSceneObject
{
    #region 参数

    /// <summary>
    /// 
    /// </summary>
    WarSoldier mTarget;
    /// <summary>
    /// 基本状态
    /// </summary>
    StateBase mState;
    /// <summary>
    /// 一般状态(目前只需要2个状态，简单切换就足够了)
    /// </summary>
    StateBase mNormal;
    /// <summary>
    /// 技能状态
    /// </summary>
    StateBase mSkill;
    #endregion
    public WarSoldier()
    {
        mNormal = new NormalState(this);
        mSkill = new SkillState(this);
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="deltTime"></param>
    public override void breath(float deltTime)
    {
        base.breath(deltTime);
    }
    /// <summary>
    /// 寻找目标
    /// </summary>
    protected WarSoldier findTarget()
    {
        return null;
    }
    /// <summary>
    /// 确认目标是否可攻击
    /// </summary>
    /// <param name="target"></param>
    /// <returns></returns>
    protected bool canAttack(WarSoldier target)
    {
        return false;
    }
    /// <summary>
    /// 攻击目标 - 
    /// </summary>
    /// <param name="target"></param>
    protected void attackTarget(WarSoldier target)
    {
    }
    /// <summary>
    /// 向目标运动驱动
    /// </summary>
    /// <param name="deltTime"></param>
    protected void move2Target(WarSoldier target, float deltTime)
    { 
    }
    /// <summary>
    /// 攻击目标驱动
    /// </summary>
    /// <param name="deltTime"></param>
    protected void attack2Target(float deltTime)
    {
    }
    /// <summary>
    /// 是否还在攻击(查询是否还在释放技能)
    /// </summary>
    protected bool isAttacking()
    {
        return false;
    }
    #region 状态

    protected void switch2Normal()
    {

    }

    protected void switch2Skill()
    {

    }

    private void switchState(StateBase state)
    {
        if(mState != null)
        {
            mState.exit();
        }
        mState = state;
        mState.enter();
    }

    abstract class StateBase
    {
        abstract public void enter();
        abstract public void exit();
        abstract public void breath(float deltTime);
    }
    /// <summary>
    /// 
    /// </summary>
    class NormalState : StateBase
    {
        /// <summary>
        /// 
        /// </summary>
        WarSoldier mPlayer;
        /// <summary>
        /// 
        /// </summary>
        WarSoldier mMoveTarget;

        public NormalState(WarSoldier player)
        {
            mPlayer = player;
        }

        public override void enter()
        {
            mMoveTarget = null;
        }

        public override void exit()
        {
        }

        public override void breath(float deltTime)
        {
            // 
            if (mMoveTarget != mPlayer.mTarget)
            {
                mMoveTarget = mPlayer.mTarget;
                //判断是否可攻击
                if (mPlayer.canAttack(mMoveTarget))
                { 
                    //可攻击 - 申请跳转状态 且返回
                    return;
                }
            }
            // 向目标前进(如果有目标 .. 实际没有没目标的时候啊)
            if (mMoveTarget != null)
            {
                mPlayer.move2Target(mMoveTarget, deltTime);
            }
        }
    }

    class SkillState : StateBase
    {
        WarSoldier mPlayer;

        public SkillState(WarSoldier player)
        {
            mPlayer = player;
        }

        public override void enter()
        {
            //攻击目标
            mPlayer.attackTarget(mPlayer.mTarget);
        }

        public override void exit()
        {
        }

        public override void breath(float deltTime)
        {
            if (mPlayer.isAttacking() == false)
            {
                //攻击结束，跳转到普通状态
            }
        }

    }
    
    #endregion
}

